class Solution(object):
    def minSubarray(self, nums, p):
        total = sum(nums)
        if total % p == 0:
            return 0
        mod = total % p
        prefix = {0: -1}
        min_len = float('inf')
        now = 0
        for index, num in enumerate(nums):
            now += num
            if (now % p - mod) % p in prefix:
                min_len = min(min_len, index - prefix[(now % p - mod) % p])
            prefix[now % p] = index
        if min_len == len(nums):
            return - 1
        return min_len